﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.OleDb;

namespace WebSite_CodeMan.BLL
{
    public class LogInfo
    {
        /// <summary>
        /// 写系统日志
        /// </summary>
        /// <param name="strNote"></param>
        /// <param name="logClass"></param>
        /// <returns></returns>
        public static bool AddSysLog(string strNote)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_LogNote",strNote),
                                           new OleDbParameter("@T_LogIP",Common.GetMes.GetIp()),
                                           new OleDbParameter("@T_DateTime",DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))};
                return (DBUnlity.AccessHelper.ExecuteNonQuery(DBUnlity.AccessHelper.ConnectionString, " INSERT INTO T_Sys_Log(T_LogNote, T_LogIP,T_DateTime) VALUES(@T_LogNote,@T_LogIP,@T_DateTime)", parm) > 0) ? true : false;
            }
            catch (Exception EX)
            {
                throw EX;
            }
        }
        /// <summary>
        /// 分页查询日志信息
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static DataTable GetAllLogInfo(int PageIndex, int PageSize, out int PageCount, out int RecordCount)
        {
            try
            {
                string strSql = " SELECT * FROM T_Sys_Log ";
                string strShow = " * ";
                return DBUnlity.AccessHelper.ExecutePager(PageIndex, PageSize, "T_LogID", strShow, strSql, "", " T_LogID DESC ", out PageCount, out RecordCount);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 删除指定的日志
        /// </summary>
        /// <param name="strAllLID"></param>
        /// <returns></returns>
        public static bool DelLogInfo(string strAllLID)
        {
            try
            {
                return DBUnlity.AccessHelper.ExecuteNonQuery(DBUnlity.AccessHelper.ConnectionString, " DELETE FROM T_Sys_Log WHERE T_LogID IN(" + strAllLID + ")", null) > 0 ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 删除所有的日志
        /// </summary>
        /// <param name="strAllLID"></param>
        /// <returns></returns>
        public static bool DelLogInfo()
        {
            try
            {
                return DBUnlity.AccessHelper.ExecuteNonQuery(DBUnlity.AccessHelper.ConnectionString, " DELETE FROM T_Sys_Log ", null) > 0 ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
